﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using System.Xml.Serialization;


namespace IKEA.FileExchange.Web
{
    public enum NotificationType
    {
        NotificationToRecipient,
        NotificationToManager
    }

    public static class EmailHelper
    {
        private const string RECIPIENT_TEMPLATE_PATH = "c://Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/LAYOUTS/FileExchangeLayouts/messages/RecipientTemplate.htm";
        private const string MANAGER_TEMPLATE_PATH = "c://Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/LAYOUTS/FileExchangeLayouts/messages/ManagerTemplate.htm";

        private const string RECIPIENT_SUBJECTS_MESSAGE = "IKEA FileExchange: New files have been uploaded";
        private const string MANAGER_SUBJECTS_MESSAGE = "IKEA FileExchange: Management link to your files";


        public static void SendEmail(string to, string uniqueId, string comments, NotificationType type, SPWeb spWeb)
        {
            string txtRecipientTemplate = System.IO.File.ReadAllText(RECIPIENT_TEMPLATE_PATH);
            string txtManagerTemplate = System.IO.File.ReadAllText(MANAGER_TEMPLATE_PATH);
            string txtTemplate = string.Empty;
            string txtSubject = string.Empty;
            string textBody = string.Empty;
             
            switch (type)
            {
                case NotificationType.NotificationToRecipient:

                    txtTemplate = txtRecipientTemplate;
                    txtSubject = RECIPIENT_SUBJECTS_MESSAGE;
                    textBody = string.Format(txtRecipientTemplate, UrlHelper.GenerateDownloadTicketPageUrl(uniqueId), comments);
                    break;

                case NotificationType.NotificationToManager:

                    txtTemplate = txtManagerTemplate;
                    txtSubject = MANAGER_SUBJECTS_MESSAGE;
                    textBody = String.Format(txtTemplate, UrlHelper.GeneratePackageManagementUrl(uniqueId), comments);
                    break;
            }

            
                
               
            

            SPUtility.SendEmail(spWeb, true, false, to, txtSubject, textBody);

        }


    }

}
